#include "Camera.h"
#include "GlobalUse.h"
#include "BaseD3D.h"

VCamera::VCamera(void)
{
}

VCamera::~VCamera(void)
{
}

void VCamera::Init()
{
	m_fAngleX = 0.0f;
	m_fAngleY = 0.0f;
	m_fAngleZ = 0.0f;

	m_v3Position = D3DXVECTOR3(0.0f,0.0f,0.0f);
	Update();
}

void VCamera::Update()
{
	D3DXVECTOR3 v3Look = D3DXVECTOR3(cosf(m_fAngleX) * sinf(m_fAngleY), cosf(m_fAngleY), sinf(m_fAngleX) * sinf(m_fAngleY));
	D3DXVECTOR3 v3Target = m_v3Position + v3Look;
	D3DXVECTOR3 v3Up = D3DXVECTOR3(0, -1, 0);
	D3DXMatrixLookAtLH(&m_matView, &m_v3Position, &v3Target, &v3Up);
	VBaseD3D* baseD3D = gfGetD3DBase();
    baseD3D->d3ddev->SetTransform(D3DTS_VIEW, &m_matView);    // set the view transform to matView 

	D3DXMATRIX matProjection;    // the projection transform matrix

	D3DXMatrixPerspectiveFovLH(&matProjection,
							   D3DXToRadian(45),    // the horizontal field of view
							   (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT,    // aspect ratio
							   1.0f,    // the near view-plane
							   100.0f);    // the far view-plane

	baseD3D->d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the projection transform
}

void VCamera::MoveX(float fDistAmount)
{
	D3DXMatrixTranslation(&m_matView,fDistAmount,0,0);
}

void VCamera::MoveY(float fDistAmount)
{
	D3DXMatrixTranslation(&m_matView,0,fDistAmount,0);
}

void VCamera::MoveZ(float fDistAmount)
{
	D3DXMatrixTranslation(&m_matView,0,0,fDistAmount);
}

void VCamera::MoveForward(float fDistAmount)
{
	m_v3Position.z += fDistAmount*sin(m_fAngleX);
	m_v3Position.x += fDistAmount*cos(m_fAngleX);
}

void VCamera::MoveBackward(float fDistAmount)
{
	m_v3Position.z -= fDistAmount*sin(m_fAngleX);
	m_v3Position.x -= fDistAmount*cos(m_fAngleX);
}

void VCamera::MoveLeft(float fDistAmount)
{
	float fLeft = m_fAngleX - PI / 2;
	m_v3Position.z += fDistAmount*sin(fLeft);
	m_v3Position.x += fDistAmount*cos(fLeft);
}

void VCamera::MoveRight(float fDistAmount)
{
	float fRight = m_fAngleX + PI / 2;
	m_v3Position.z += fDistAmount*sin(fRight);
	m_v3Position.x += fDistAmount*cos(fRight);
}

void VCamera::RotateX(float fAngleAmount)
{
	m_fAngleX += fAngleAmount;
}

void VCamera::RotateY(float fAngleAmount)
{
	m_fAngleY += fAngleAmount;
}

void VCamera::RotateZ(float fAngleAmount)
{
	m_fAngleZ += fAngleAmount;
}

float VCamera::GetAngleX()
{
	return m_fAngleX;
}

float VCamera::GetAngleY()
{
	return m_fAngleY;
}

float VCamera::GetAngleZ()
{
	return m_fAngleZ;
}

void VCamera::Release()
{
}
